<script setup>
  import * as echarts from 'echarts';
  import { ref, onMounted } from 'vue';
  //获取DOM节点
  let charts = ref();
  //组件挂载完毕
  onMounted(() => {
    //一个容器可以同时展示多种类型的图形图标
    let mychart = echarts.init(charts.value);
    let option = {
      title: {
        text: '',
      },
      radar: {
        // shape: 'circle',
        indicator: [
          { name: '消费' },
          { name: '好感' },
          { name: '出行' },
          { name: '小吃' },
          { name: '爱好' },
          { name: '景点' }
        ],
        // 添加这些配置来优化刻度和整体显示效果
        splitNumber: 5, // 设置合适的分割段数
        splitLine: {
          lineStyle: {
            color: ['rgba(255,255,255,0.1)', 'rgba(255,255,255,0.2)', 'rgba(255,255,255,0.3)', 'rgba(255,255,255,0.4)', 'rgba(255,255,255,0.5)']
          }
        },
        splitArea: {
          show: false // 隐藏分割区域，减少视觉干扰
        },
        axisLine: {
          lineStyle: {
            color: 'rgba(255,255,255,0.2)'
          }
        },
        axisName: {
          color: 'white',
          fontSize: 12,
          padding: 3 // 调整文字与轴线的距离
        },
        axisTick: {
          show: true,
          lineStyle: {
            color: 'rgba(255,255,255,0.3)'
          }
        }
      },
      series: [
        {
          name: 'Budget vs spending',
          type: 'radar',
          data: [
            {
              value: [4200, 3000, 20000, 35000, 50000, 18000],
              name: '购物'
            },
            {
              value: [5000, 14000, 28000, 26000, 42000, 21000],
              name: '吃饭'
            }
          ],
          // 设置线条和区域样式以提高可读性
          lineStyle: {
            width: 2
          },
          areaStyle: {
            opacity: 0.3
          },
          emphasis: {
            lineStyle: {
              width: 3
            }
          }
        }
      ]
    };
    //设置配置项
    mychart.setOption(option);

    // 添加响应式调整
    window.addEventListener('resize', () => {
      mychart.resize();
    });
  });
</script>
<template>
  <div class="box">
    <div class="top">
      <div>
        <p class="title">数据统计</p>
        <img
          src="../../images/dataScreen-title.png"
          alt=""
        >
      </div>
    </div>
    <div
      class="charts"
      ref="charts"
    ></div>
  </div>
</template>

<style scoped>
  .box {
    background: url(../../images/dataScreen-main-cb.png) no-repeat;
    background-size: 100% 100%;
    margin-top: 10px;
    height: 100%;
  }

  .top {
    margin-left: 20px;
    height: 70px;
    display: flex;
    align-items: center;
  }

  .top .title {
    color: white;
    font-size: 20px;
  }

  .top img {
    margin-top: 10px;
  }

  .charts {
    height: calc(100% - 80px);
  }
</style>